package com.reflection.homework;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class h1_类型擦除 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(123);
        System.out.println(list);
//        list.add("aaa"); //无法添加

        //通过反射添加
        Class clazz = list.getClass();
        //类型擦除,之后可以添加任意类型()
        Method m = clazz.getMethod("add", Object.class);
        m.invoke(list,"aaa");   //添加字符串

        System.out.println(list);
    }
}
